﻿@model StudentViewModels
@{
    ViewData["Title"] = "添加学生";
}

<h1>@ViewData["Title"]</h1>
<form asp-action="CreateStudent" asp-controller="home" method="post" class="m-3" enctype="multipart/form-data">
    @* enctype="multipart/form-data"不对表单在http传输流中进行格式处理（比如）空格转化+号等 *@
    <input asp-for="@Model.Id" hidden="hidden" />
    <div class="form-group row">
        <label asp-for="@Model.SNo" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="@Model.SNo" class="form-control" />
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="@Model.Name" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="@Model.Name" class="form-control" />
            <span asp-validation-for="@Model.Name"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="@Model.MId" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <select asp-for="@Model.MId" asp-items="@ViewBag.SelectItem">
                <option>--请选择--</option>
            </select>
            <span asp-validation-for="@Model.MId"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="@Model.TelPhone" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="@Model.TelPhone" class="form-control" />
            <span asp-validation-for="@Model.TelPhone"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="@Model.Email" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="@Model.Email" class="form-control" />
            <span asp-validation-for="@Model.Email"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="@Model.Birthday" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="@Model.Birthday" class="form-control" />
            <span asp-validation-for="@Model.Birthday"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="@Model.Gender" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <select asp-for="@Model.Gender" asp-items="@Html.GetEnumSelectList<GenderEnum>()">
                <option>--请选择--</option>
            </select>
            <span asp-validation-for="@Model.Gender"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="@Model.ImgFile" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <div class="custom-file">
                <input asp-for="@Model.ImgFile" class="form-control custom-file-input" />
                <label class="custom-file-label">请选择照片....</label>
            </div>
        </div>
    </div>
    <button type="submit" class="btn btn-success mt-2">创建</button>
    <br />
    <a asp-action="index" asp-controller="home" class="btn btn-outline-primary mt-2 col-sm-2">返回学生列表</a>
</form>

@section Scripts{
    <script type="text/javascript">
        $(".custom-file-input").on("change", function () {
            var fileName = $(this).val().split("\\").pop();//获取文件路径
            $(this).next(".custom-file-label").html(fileName);
        })
    </script>
}

